home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 5
/
MacMania 5.toast
/
/
Internet software
/
NewsWatcher
/
NW Source
/
Source
/
newart.c
< prev
next >
Wrap
Text File
|
1997-01-09
|
3KB
|
119 lines
/*----------------------------------------------------------------------------
newart.c
This module handles checking for new articles.
Copyright © 1994-1997, Northwestern University.
----------------------------------------------------------------------------*/
#include <string.h>
#include "glob.h"
#include "newart.h"
#include "news.h"
#include "mark.h"
#include "newswatcher.h"
#include "status.h"
#include "memutil.h"
#include "dialog.h"
#include "group.h"
#include "biglist.h"
/*----------------------------------------------------------------------------
DoCheckNewArticles
Check to see if there are any new articles on the server for all of the
groups in a user group list.
Entry: wind = pointer to user group list window.
Exit: function result = error code.
----------------------------------------------------------------------------*/
OSErr DoCheckNewArticles(WindowPtr wind)
{
TWindow **info;
BigListRef groupList;
TGroup **groupArray;
long numGroups, numItems, groupIndex, item;
TGroup theGroup;
long numUnread;
Boolean haveSelectedGroup;
OSErr err = noErr;
err = DisplayStatusMessageNumber(kStrChecking);
if (err != noErr) return err;
info = (TWindow**)GetWRefCon(wind);
groupArray = (**info).groupArray;
numGroups = (**info).numGroups;
groupList = (**info).groupList;
numItems = BigLGetNumItems(groupList);
/* Close all child windows. */
while ((**info).childList != nil) {
err = DoClose((**(**info).childList).childWindow);
if (err != noErr) return err;
}
/* Add [lastMess+1, maxlong] to the end of each group unread list.
Mark each group in the list for an article range update. */
for (item = 0; item < numItems; item++) {
groupIndex = BigLGetData(groupList, item);
theGroup = (*groupArray)[groupIndex];
numUnread = theGroup.numUnread;
err = AppendUnreadRange(theGroup.lastMess+1, kMaxLong, &theGroup);
if (err != noErr) return err;
theGroup.numUnread = numUnread;
theGroup.status = 'x';
(*groupArray)[groupIndex] = theGroup;
}
/* Get new group article ranges from server. */
err = GetGroupArrayArticleRanges(groupArray, numGroups);
/* Adjust unread lists and redraw unread article counts. Select the first
group with unread articles, if any. Note that we must do this even if
we get an error from the call to GetGroupArrayArticleRanges above,
because we have mucked with the unread lists in the group array, and
we must put them back the way they were. */
haveSelectedGroup = false;
for (item = 0; item < numItems; item++) {
groupIndex = BigLGetData(groupList, item);
theGroup = (*groupArray)[groupIndex];
if (theGroup.status == 'x') {
AdjustUnreadList(&theGroup);
(*groupArray)[groupIndex] = theGroup;
RedrawUnreadCount(wind, item);
if (haveSelectedGroup || theGroup.numUnread == 0) {
BigLSelect(groupList, item, false);
} else {
BigLSelect(groupList, item, true);
haveSelectedGroup = true;
}
} else {
DisposeGroupUnreadList(&theGroup);
theGroup.firstMess = 1;
theGroup.lastMess = 0;
(*groupArray)[groupIndex] = theGroup;
RedrawUnreadCount(wind, item);
BigLSelect(groupList, item, false);
}
}
if (haveSelectedGroup) BigLScrollItemIntoView(groupList,
BigLGetFirstSelectedItem(groupList),
kBigLScrollToTop, kBigLScrollToBottom);
/* Return the error code from the call to GetGroupArrayArticleRanges. */
return err;
}